from pprint import pprint


"""
student = {"name": "jackie", "age": 10}

name = "linda"
age = 20

newObj = [{name: name, age: age}]
print(newObj)



def operate(*args):
    a, b, c = args
    print(f"a={a},b={b},c={c}")


def create_person(a, b, c, name="xxx", age=10):
    print(f"a={a},b={b},c={c},name={name},age={age}")


x_tuple = (10, 20, 30)
nums = [1, 2, 3]
person = {"name": "linda", "age": 20}

operate(*x_tuple)
create_person(*nums, **person)


print(True + True)

name_set = {"linda", "jackie", "susan"}
num_set = {1, 2, 3, 4, 5}
print(f"python中的set={num_set}")
num_set.add(6)
print(f"python中的set={num_set}")

for i, item in enumerate(name_set):
    print(f"i==={i},item={item}")



# is
# 比较对象：
# 引用类型的比较即它们在内存中的存储地址是否不同
# 值类型的应该存储的值的内存地址
x = y = z = 1
m = n = "jackie"

print(x is y)
print(m is n)


# 定义两个短字符串，它们可能被缓存
str1_cached = "hello"
str2_cached = "hello"

# 比较 str1_cached 和 str2_cached 是否是同一个对象
# 预期输出：True，因为短字符串通常会被缓存，它们引用的是同一个对象
print(f"str1_cached is str2_cached: {str1_cached is str2_cached}")
print(f"address_str1_cached={id(str1_cached)},\naddress_str2_cached={id(str2_cached)}")


# 定义两个长字符串或动态生成的字符串，通常不会被缓存
str1_uncached = "hello" * 10000
str2_uncached = "hello" * 10000

# 比较 str1_uncached 和 str2_uncached 是否是同一个对象
# 预期输出：False，因为长字符串通常不会被缓存，它们是两个不同的对象
print(f"str1_uncached is str2_uncached: {str1_uncached is str2_uncached}")
# 比较 str1_uncached 和 str2_uncached 是否不是同一个对象
# 预期输出：True
print(f"str1_uncached is not str2_uncached: {str1_uncached is not str2_uncached}")


m = None
n = None

print(m is n)


test_file_unit_list = ["B", "KB", "MB", "GB", "TB"]
basic_file_size = 1024

test_file_size_list = ["500", "1987", "1083712", "3812112876"]


def formate_file_size(file_size_byte):

    file_unit_index = 0
    float_file_size_byte = float(file_size_byte)
    if float_file_size_byte is None:
        return 0
    elif float_file_size_byte <= basic_file_size:
        file_unit_index = 0
    else:

        while float_file_size_byte > basic_file_size:
            float_file_size_byte = float_file_size_byte / basic_file_size
            file_unit_index += 1

    # print(f"file_unit_index==={file_unit_index}")

    return f"{float(file_size_byte):.2f}={float_file_size_byte}{test_file_unit_list[file_unit_index]}"


for i, file_size in enumerate(test_file_size_list):
    formate_size = formate_file_size(file_size)
    print(f"{file_size} 个字节的文件大小为：{formate_size}")




# 元组解包
stu = [("linda", 20, 98), ("susan", 20, 10)]
for name, age, score in stu:
    print(f"name={name},age={age},score={score}")

# 字典解包
person = {"name": "linda", age: 10}
name, age = person
print(f"name={name},age={age}")

# 列表推导
nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
h = i = j = 100

print(f"h is i= {h is i},h is j={h is j}, i is j={i is j}")

print(f"nums在内存中地址为：{id(nums)}")

xx = 100
yy = xx
print(f"xx is yy={xx is yy}, xx is h=={xx is h}")

xx = 2000
print(f"xxx=={xx},h==={h},yy==={yy}")


x = 5
print(f"od x 地址={id(x)}")
x = x + 1
print(f"新 x={id(x)}")


numlist = [1, 2, 3]
print(f"列表numlist的地址：{id(numlist)}")

numlist.append(4)

print(f"列表numlist的地址：{id(numlist)}")

person_map = {"name": "linda"}
print(f"1.person_name在内存中地址：{id(person_map)}")

person_map["age"] = 100

print(f"2.person_name在内存中地址：{id(person_map)}")


t = (1, 2, [3, 4])
num1, num2, lst = t
print(f"num1={num1},num2={num2},lst={lst},lst_地址={id(lst)}")

lst.append(5)

print(f"lst_地址={id(lst)}")
"""


def modify_list(lst):
    """修改列表（可变对象）"""
    lst.append(4)
    print(f"函数内 lst: {lst}, id: {id(lst)}")


def modify_number(num):
    """修改数字（不可变对象）"""
    num = num + 1
    print(f"函数内 num: {num}, id: {id(num)}")


def reassign_list(lst):
    """重新赋值列表"""
    lst = [7, 8, 9]  # 创建新对象
    print(f"函数内 lst: {lst}, id: {id(lst)}")


# 测试可变对象
my_list = [1, 2, 3]
print(f"调用前: {my_list}, id: {id(my_list)}")
modify_list(my_list)

print(
    f"调用后: {my_list},my_list的地址不不变={id(my_list)}"
)  # [1, 2, 3, 4] - 被修改了！

# 测试不可变对象
my_num = 10
print(f"\n调用前: {my_num}, id: {id(my_num)}")
modify_number(my_num)
print(f"调用后: {my_num}")  # 10 - 没有被修改

# 测试重新赋值
print(f"\n调用前: {my_list}, id: {id(my_list)}")
reassign_list(my_list)
print(f"调用后: {my_list}")  # [1, 2, 3, 4] - 没有被修改


set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}

# 方法1: symmetric_difference() 或 ^ 运算符
sym_diff1 = set1.symmetric_difference(set2)
sym_diff2 = set1 ^ set2
print(sym_diff1)  # {1, 2, 5, 6}
print(sym_diff2)  # {1, 2, 5, 6}

set3 = {1, 2, 3}
set3.clear()
print(f"清空之后的set3={set3}")
set3.add(100)
print(f"set3={set3}")

# [1,2,3]
# [4,5,6]
# [7,8,9]

martix_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

martix_list[1][2] = 100
print(martix_list)

martix_tuple = (1, 2, [3, 4], 5)
martix_tuple_unvariable = (1, 2, 3, 4, 5)


martix_tuple[2].append(100)
print("martix_tuple=", martix_tuple)

mix_dict = {}

for idx, item in enumerate(martix_tuple_unvariable):
    mix_dict[item] = martix_tuple_unvariable[idx]

print("mix_dict=", mix_dict)

import copy

copy_list = ["123", (1, 2, 3)]

str_1 = "123"
str_2 = copy.deepcopy(str_1)

print(id(str_1), id(str_2))


class Person:

    def __init__(self, name, age):
        self.name = name
        self.age = age


person = Person("linda", 20)

if hasattr(person, "__dict__"):
    print(person.__dict__.items())

from collections import namedtuple

PersonTuple = namedtuple("PersonTuple", "name,age")

person_tupe = PersonTuple("jackie", 12)

print(person_tupe.name)

print(hasattr(person_tupe, "name"))


print(bool(""))
